/**
 * MasicComponent
 * <p/>
 * User: joakimd
 * Date: 2013-03-11
 * Time: 11:17
 */
package org.dru.masic {
public class MasicComponent extends MasicObject {
    private var _inputs: Vector.<MasicInput>;
    private var _outputs: Vector.<MasicOutput>;
    private var _parameters: Vector.<MasicParameter>;

    private var _parent: MasicContainer;

    public function MasicComponent() {
        _inputs = new Vector.<MasicInput>();
        _outputs = new Vector.<MasicOutput>();
        _parameters = new Vector.<MasicParameter>();
    }

    public final function set name(value: String): void {
        setName(name)
    }

    internal final function get inputs(): Vector.<MasicInput> {
        return _inputs;
    }

    public final function get numInputs(): int {
        return inputs.length;
    }

    public final function getInputAt(index: int): MasicInput {
        return inputs[index];
    }

    public final function getInputIndex(input: MasicInput): int {
        return inputs.indexOf(input);
    }

    protected final function createInput(name: String, stereo: Boolean): MasicInput {
        const input: MasicInput = new MasicInput(this, name, stereo);
        inputs.push(input);
        return input;
    }

    public final function removeAllSources(): void {
        for each (var input: MasicInput in inputs) {
            input.removeAllSources();
        }
    }

    internal final function get outputs(): Vector.<MasicOutput> {
        return _outputs;
    }

    public final function get numOutputs(): int {
        return outputs.length;
    }

    public final function getOutputAt(index: int): MasicOutput {
        return outputs[index];
    }

    public final function getOutputIndex(output: MasicOutput): int {
        return outputs.indexOf(output);
    }

    protected final function createOutput(name: String, stereo: Boolean): MasicOutput {
        const output: MasicOutput = new MasicOutput(this, name, stereo);
        outputs.push(output);
        return output;
    }

    public final function removeAllTargets(): void {
        for each (var output: MasicOutput in outputs) {
            output.removeAllTargets();
        }
    }

    public final function removeAllConnections(): void {
        removeAllSources();
        removeAllTargets();
    }

    internal final function get parameters(): Vector.<MasicParameter> {
        return _parameters;
    }

    public final function get numParameters(): int {
        return parameters.length;
    }

    public final function getParameterAt(index: int): MasicParameter {
        return parameters[index];
    }

    public final function getParameterIndex(parameter: MasicParameter): int {
        return parameters.indexOf(parameter);
    }

    protected final function createParameter(name: String, steps: int, value: Number, encoder: Function, decoder: Function): MasicParameter {
        const parameter: MasicParameter = new MasicParameter(this, name, steps, value, encoder, decoder);
        parameters.push(parameter);
        return parameter;
    }

    public final function resetAllParameters(): void {
        for each (var parameter: MasicParameter in parameters) {
            parameter.resetValue();
        }
    }

    public final function get parent(): MasicContainer {
        return _parent;
    }

    internal final function setParent(value: MasicContainer): void {
        _parent = value;
    }

    public function processTick(samplesToTick: int): void {

    }

    public function processSamples(start: int, end: int): void {
    }

    public function processNote(note: int, velocity: Number): void {
    }
}
}
